<?php
require "./common/function.php";

$id = $_POST['pid'];
$buyNum = $_POST['num'];
if($_POST){
//加入购物车
    $sql = "insert into t_product_order(pid,buynum) values($id,$buyNum)";
    $insertRes = getMySql($sql,'加入购物车失败');
    if($insertRes){
//查询购物车商品信息
        display();
    }else{
        require "./productInfo.php?a=add&id=".$id;
        exit;
    }
}

display();

function display(){
    $sql2="SELECT a.buynum,b.id,b.name,b.price FROM t_product_order a LEFT JOIN t_product b ON a.pid = b.id where a.oid is NULL and b.`status`=0 ORDER BY a.id desc";
    $result = getMySql($sql2,'查询购物车信息失败');
    if($result){
        if(mysqli_num_rows($result)){
            $proResults = mysqli_fetch_all($result,MYSQLI_ASSOC);
        }
    }
    require "./html/addProOrder.html";
    exit;
}
